package com.rocketmq.service.impl;

import com.alibaba.fastjson.JSON;
import com.rocketmq.dao.IOrderMapper;
import com.rocketmq.entity.Order;
import com.rocketmq.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements IOrderService {

    @Autowired
    private IOrderMapper orderMapper;

    @Override
    public String getOrderInfo(int userId) {
        List<Order> orderInfo = orderMapper.getOrderInfo(userId);
        return JSON.toJSONString(orderInfo);
    }

    @Override
    public String pay(int productId, int userId) {
        Order order = orderMapper.getOrderInfoByProductId(userId, productId);
        orderMapper.updateStatus(order.getId(), 1);

        return "success";
    }

    @Override
    public String pay(int orderId) {
        orderMapper.updateStatus(orderId, 1);
        return "支付成功";
    }

}
